package com.rxt.common.aop;

import com.alibaba.fastjson.JSON;
import com.rxt.common.result.Result;
import com.rxt.model.dto.KKonwledgeDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;

@Component
@Aspect //切面  定义了通知和切点的关系
@Slf4j
public class SelectHotKnowledgeAspect {

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    @Pointcut("@annotation(com.rxt.common.aop.SelectHotKnowledge)")
    public void pt(){}

    //环绕通知
    @Around("pt()")
    public Object dos(ProceedingJoinPoint joinPoint) throws Throwable {

        //走原始方法
        Result result = (Result)joinPoint.proceed();

        KKonwledgeDto data = (KKonwledgeDto)result.getData();
        Long id = data.getId();
        String key = "hot_list";
        redisTemplate.opsForZSet().incrementScore(key,id,1);
        return result;
    }

}
